package servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet(value = "/life",loadOnStartup = -1)
public class ServletLife extends HttpServlet{
    private static int counter = 0;
    public ServletLife() {
        super();
        System.out.println("ServletLife: " + ++counter + " instances");
    }

    //初始化servlet
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        System.out.println("ServletLife:invoke init() " + new Date().toString());
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("ServletLife: invoke doPost " + new Date().toString());
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("ServletLife: invoke doGet() " + new Date().toString());
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("ServletLife: invoke service() "+new Date().toString());
        super.service(req, resp);
    }

    @Override
    public void destroy() {
        System.out.println("ServletLife: invoke destroy() " + new Date().toString());
    }

}
